import rtconfig
Import('RTT_ROOT')
from building import *

# get current directory
cwd = GetCurrentDir()

# The set of source files associated with this SConscript file.
src = Split("""
CMSIS/CM3/DeviceSupport/ST/STM32F2xx/system_stm32f2xx.c
STM32F2xx_StdPeriph_Driver/src/misc.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_adc.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_can.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_crc.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_cryp.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_cryp_aes.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_cryp_des.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_cryp_tdes.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dac.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dbgmcu.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dcmi.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_dma.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_exti.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_flash.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_fsmc.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_gpio.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_hash.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_hash_md5.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_hash_sha1.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_i2c.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_iwdg.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_pwr.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rcc.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rng.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_rtc.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_sdio.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_spi.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_syscfg.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_tim.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_usart.c
STM32F2xx_StdPeriph_Driver/src/stm32f2xx_wwdg.c
""")

# starupt scripts for STM32F2xx
startup_scripts = 'startup_stm32f2xx.s'

# add for startup script
if rtconfig.CROSS_TOOL == 'gcc':
    src = src + ['CMSIS/CM3/DeviceSupport/ST/STM32F2xx/startup/gcc_ride7/' + startup_scripts]
elif rtconfig.CROSS_TOOL == 'keil':
    src = src + ['CMSIS/CM3/DeviceSupport/ST/STM32F2xx/startup/arm/' + startup_scripts]
elif rtconfig.CROSS_TOOL == 'iar':
    src = src + ['CMSIS/CM3/DeviceSupport/ST/STM32F2xx/startup/iar/' + startup_scripts]

path = [cwd + '/STM32F2xx_StdPeriph_Driver/inc',
    cwd + '/CMSIS/CM3/DeviceSupport/ST/STM32F2xx']

if GetDepend(['RT_USING_BSP_CMSIS']):
    path += [cwd + '/CMSIS/CM3/CoreSupport']
    src += [cwd + '/CMSIS/CM3/CoreSupport/core_cm3.c']
elif GetDepend(['RT_USING_RTT_CMSIS']):
    path += [RTT_ROOT + '/components/CMSIS/Include']

if GetDepend('RT_USING_LWIP') == True:
	src = src + ['STM32F2x7_ETH_Driver/src/stm32f2x7_eth.c']
	path = path + [cwd + '/STM32F2x7_ETH_Driver/inc']
	

CPPDEFINES = ['USE_STDPERIPH_DRIVER']
group = DefineGroup('STM32_StdPeriph', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)

Return('group')
